home *** CD-ROM | disk | FTP | other *** search
- Path: news.ti.com!usenet
- From: Chuach@dlep1.itg.ti.com (Chua Chye Heng)
- Newsgroups: comp.lang.c++
- Subject: HELP!! How to correctly pass member functions to a C function???
- Date: Wed, 10 Apr 1996 01:19:51 GMT
- Organization: Texas Instruments
- Message-ID: <4kf534$csn@tilde.csc.ti.com>
- NNTP-Posting-Host: 137.167.42.30
- X-Newsreader: Forte Free Agent 1.0.82
-
- Hi,
-
- I need to use a function in a c library which search some database and
- invoke the user defined function to process them in my c++ program.
- /* c function prototype */
- search( int (*norm_func)(), int (*err_func)());
-
- My class definitions are as follows:
- extern "C" {
- #include "C-function.h"
- }
-
- class base {
- ...
- public:
- int process();
- virtual int good_handle( data* pData ) = 0;
- virtual int bad_handle( char* msg )=0;
- }
-
- class derived : public base {
- ...
- public:
- int good_handle( data* pData );
- int bad_handle( char* msg);
- }
-
- I use the process method in the base class to invoke the C function
- like this:
- search ( (int(*)())this->good_handle, (int(*)())this->bad_handle);
-
- When the program executes, the good_handle method in the derived class
- did get called. BUT the data* pData points to some "&^%$#" instead!!
- I did try to use a normal C program to test out the library and it is
- working fine.
-
- Can some kind people help me out of this?? My project schedule is
- falling on me..... HELP
-
- Deeply appreciate any hints or help..
-
- BTW, I also try to use a normal C function to wrap around the two
- method but it also fail
- base* pBase;
- int good( ...) { pBase->good_handle(...); }
- int bad(...) { pBase->bad_handle(...); }
- and called them in process as:
- search (good_handle, bad_handle);
-
-
- ===========================================================
- Chye Heng
- Email: Chuach@dlep1.itg.ti.com
- Voice: 065-2902460
-
-
-